package com.computergames.server.protocol;

import com.computergames.server.message.Message;
import com.computergames.server.message.MoveRequestMessage;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;

public class MoveRequestMessageAdapterFactory implements TypeAdapterFactory {

    @Override
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
        Class<? super T> rawType = type.getRawType();
        if (rawType != Message.class && !MoveRequestMessage.class.isAssignableFrom(rawType)) {
            return null; // 不处理非Message或其子类MoveRequestMessage的类型
        }
        // 确保 MoveRequestMessageTypeAdapter 能够访问到 Gson 实例
        return (TypeAdapter<T>) new MoveRequestMessageTypeAdapter(gson);
    }
}